<?php

namespace search\controllers\bigdata;

use business\elasticsearch\services\BigDataProjectLifeCycleService;

class ProjectLifeCycleController extends BaseController
{
    public $enableCsrfValidation = false;//csrf安全

    /**
     *
     * @api {get} /bigdata/project-life-cycle/get-list 项目合并，生命周期
     *
     * @apiVersion 1.0.0
     * @apiGroup bigdataDeveloper
     *
     * @apiDescription 项目合并
     *
     * @apiParam {String} keyword                   搜索词
     * @apiParam {String} area_code                 项目地区
     * @apiParam {String} land_usage                土地用途
     * @apiParam {String} project_type              工程用途
     * @apiParam {String} fitment_fee               装修类型
     *
     * @apiParam {String} company_area_code         企业地区
     * @apiParam {String} company_type              企业类型
     * @apiParam {String} company_label             企业标签
     * @apiParam {String} industry_category         行业分类
     * @apiParam {Number} page                      页码
     * @apiParam {Number} pageSize                  分页size
     *
     * @apiSuccess {Boolean} success                    返回状态
     * @apiSuccess {String}  message                    返回消息内容
     * @apiSuccess {Number}  errorCode                  错误码
     * @apiSuccess {Object}  data                       对象数组
     */
    public function actionGetList()
    {
        try {
            $id = $this->getParam('id');
            $keyword = $this->getParam('keyword');
            $areaCode = $this->getParam('area_code');//多个用,分隔
            $landUsage = $this->getParam('land_usage');//土地用途 多个用,分隔
            $projectType = $this->getParam('project_type');//工程用途 多个用,分隔
            $fitmentFee = $this->getParam('fitment_fee');//装修类型 多个用,分隔
            $takeLandDateStart = $this->getParam('take_land_date_start');//拿地日期
            $takeLandDateEnd = $this->getParam('take_land_date_end');
            $projectDateStart = $this->getParam('project_date_start');
            $projectDateEnd = $this->getParam('project_date_end');//立项日期
            $buildDateStart = $this->getParam('building_date_start');
            $buildDateEnd = $this->getParam('building_date_end');//开工日期
            $openDateStart = $this->getParam('open_date_start');
            $openDateEnd = $this->getParam('open_date_end');//开盘日期
            $completedDateStart = $this->getParam('completed_date_start');
            $completedDateEnd = $this->getParam('completed_date_end');//竣工日期
            $companyAreaCode = $this->getParam('company_area_code');//多个用,分隔
            $companyType = $this->getParam('company_type');//多个用,分隔
            $companyLabel = $this->getParam('company_label');//多个用,分隔
            $industryCategory = $this->getParam('industry_category');//多个用,分隔
            $organizingCode = $this->getParam('organizing_code');//企业信用代码，多个用,分隔
            $projectPriceGtAvgLabel = $this->getParam('project_price_gt_avg_label');//项目高端标签
            $page = $this->getParam('page');
            $pageSize = $this->getParam('page_size');
            $page = intval($page) > 0 ? intval($page) : 1;
            $pageSize = intval($pageSize) > 0 ? intval($pageSize) : 10;

            $areaCode = array_filter(explode(",", $areaCode));
            $landUsage = array_filter(explode(",", $landUsage));
            $projectType = array_filter(explode(",", $projectType));
            $fitmentFee = array_filter(explode(",", $fitmentFee));
            $companyAreaCode = array_filter(explode(",", $companyAreaCode));
            $companyType = array_filter(explode(",", $companyType));
            $companyLabel = array_filter(explode(",", $companyLabel));
            $industryCategory = array_filter(explode(",", $industryCategory));
            $organizingCode = array_filter(explode(",", $organizingCode));
            $projectPriceGtAvgLabel = array_filter(explode(",", $projectPriceGtAvgLabel));

            $bigDataPurchaseService = new BigDataProjectLifeCycleService();
            $rs = $bigDataPurchaseService->getList(
                $keyword,
                $id,
                $areaCode,
                $landUsage,
                $projectType,
                $fitmentFee,
                $takeLandDateStart,
                $takeLandDateEnd,
                $projectDateStart,
                $projectDateEnd,
                $buildDateStart,
                $buildDateEnd,
                $openDateStart,
                $openDateEnd,
                $completedDateStart,
                $completedDateEnd,
                $companyAreaCode,
                $companyType,
                $companyLabel,
                $industryCategory,
                $organizingCode,
                $projectPriceGtAvgLabel,
                $page,
                $pageSize
            );
            return $this->success($rs);

        } catch (\Exception $ex) {
            \Yii::error($ex->getMessage());
            return $this->error('', '获取失败，请稍后重试');
        }
    }

    public function actionFuzzySearch()
    {
        try {
            $keyword = $this->getParam('keyword');
            $pageSize = $this->getParam('page_size');
            $pageSize = intval($pageSize) > 0 ? intval($pageSize) : 10;

            $bigDataDeveloperService = new BigDataProjectLifeCycleService();
            $rs = $bigDataDeveloperService->guessName($keyword, $pageSize);
            return $this->success($rs);
        } catch (\Exception $ex) {
            \Yii::error($ex->getMessage());
            return $this->error('', '获取失败，请稍后重试');
        }
    }
}
